import { Singleton } from "../../../com/gengine/core/Singleton";
import { GMapInfo } from "./info/GMapInfo";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
type int = number;
//class GameMapConfig
    
    export  class GameMapConfig extends Singleton
    {
        constructor()
        {
            
            super();this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._npcMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapVersion = new Map<any, any> /* flash.utils.Dictionary */();
            this.init();
            return;
        }

        public getVersionById(arg1: int): string
        {
            return this._mapVersion[arg1];
        }

        public getMapInfo(arg1: int): GMapInfo
        {
            return this._map[arg1];
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=arg1.map;
            for(loc2 of loc5) 
            {
                loc1 = new GMapInfo();
                loc1.id = loc2.id;
                loc1.name = loc2.name;
                loc1.hasBossPoint = loc2.hasBossPoint;
                loc1.version = loc2.version;
                loc1.des = loc2.des;
                this._mapVersion[loc1.id] = loc1.version;
                loc1.copyid = loc2.copyid;
                this._map[loc1.id] = loc1;
                if (!loc2.hasOwnProperty("npc")) 
                {
                    continue;
                }
                if (typeof loc2.npc === "array") 
                {
                    var loc6=0;
                    var loc7=loc2.npc;
                    for(loc3 of loc7) 
                    {
                        this.addNPCToType(loc1.id, loc3);
                    }
                    continue;
                }
                if (typeof !(loc2.npc === "object")) 
                {
                    continue;
                }
                this.addNPCToType(loc1.id, loc2.npc);
            }
            return;
        }

        /* internal  */addNPCToType(arg1: int, arg2: Object): void
        {
            if (arg2 == null) 
            {
                return;
            }
            var loc1=this._npcMap[arg2.type];
            if (loc1 == null) 
            {
                var loc2;
                loc1 = loc2 = [];
                this._npcMap[arg2.type] = loc2;
            }
            loc1.push({"id": arg1, "text": arg2.npcId});
            return;
        }

        public getNpcByType(arg1: string): Array<any>
        {
            return this._npcMap[arg1];
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getObjectByFileName("gameMap.xml");
            this.write(loc1);
            return;
        }

        public static get instance(): GameMapConfig
        {
            if (GameMapConfig._instance == null) 
            {
                GameMapConfig._instance = new GameMapConfig();
            }
            return GameMapConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapVersion: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_npcMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: GameMapConfig;
    }
